#ifndef LAURIN_IP_RANGE_H_
#define LAURIN_IP_RANGE_H_

#include <libnet.h>
#include <netinet/in.h>


/**
 * This class rappresent a range of ip.
 * The range is automatically generated from a network address and its subnet mask.
 * From the range they are removed the network address and the broadcast address
 *
 * The class implement a sort of iterator: it save the last readed ip and the next() method is implemented.
 */

class LaurinIPRange
{
	public:

		LaurinIPRange(const LaurinIPRange& range);

		static LaurinIPRange* getIPRange(u_int32_t networkAddress, u_int32_t subnetMask);

		u_int32_t getFirstIPAddress() const;
		u_int32_t getLastIPAddress() const;
		u_int32_t getCurrentIPAddress() const;
		int getNumbersOfIPAddress() const;

		/*
		 * Return the next ip address.
		 * Pay attention that cyclic order is implemented.
		 *
		 * Is the same of:
		 * next();
		 * return getCurrentIPAddress();
		 */
		u_int32_t getNextIPAddress();


		/*
		 * Only read the next ip address.
		 */
		void next();
		void reset();

	private:

		u_int32_t _start;
		u_int32_t _end;
		int _curOffset;
		int _nIPs;

		struct in_addr _curIP;

		LaurinIPRange();

};

#endif
